#!/bin/bash
. ./var
. ./Tmpdir

Install_Git(){
    Git_version="v2.26.2.zip"
    TAR_Git="git-2.26.2"
    GIT_HOME="/usr/local/git"

    # 调用Tmpdir
    Tmpdir
    cd $dir && wget -V &> /dev/null || yum -y install wget

    # Check for installation
    [ -d /usr/local/git-2.26.2 ] && echoRed "检测到/usr/local下已安装git，故而退出！" && rm -rf $dir && exit 1
    [ -d ${GIT_HOME} ] && echoRed "检测到/usr/local下已安装git，故而退出！" && rm -rf $dir && exit 1
    command -v git && echoRed "检测到已安装git命令，故而退出！" && rm -rf $dir && exit 1


    #安装依赖包：
    yum install -y curl-devel expat-devel gettext-devel openssl-devel zlib-devel gcc perl-ExtUtils-MakeMaker unzip


    sleep 6

    #下载git
    wget $ip/${Git_version}
    #wget https://github.com/git/git/archive/${Git_version}
    unzip ${Git_version}
    sleep 6
    cd ${TAR_Git}

    #安装git
    make prefix=${GIT_HOME} all
    make prefix=${GIT_HOME} install
    sleep 6

    # Delete the previous version,因为安装gettext-devel包就依赖git
    yum remove -y git
#    rm -rf /usr/bin/git
    ln -sv ${GIT_HOME}/bin/git /usr/bin/git
    sleep 6
    # echo "GIT_HOME=${GIT_HOME}" >> /etc/profile && echo 'PATH=$PATH:${GIT_HOME}/bin' >> /etc/profile  >> /etc/profile
    # source /etc/profile
    git --version
    sleep 6
    ${GIT_HOME}/bin/git --version &> /dev/null && echoGreen "已完成安装，可尽情享用！" || echoYellow "可能安装有问题，请检查！"

    # Clear temporary directory
    S && rm -rf $dir
}
